home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_02 / portable / pnoutref.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  3.6 KB  |  129 lines

  1. #ifndef NO_MEMORY_H
  2. #include <memory.h>
  3. #endif
  4. #define    CURSES_LIBRARY    1
  5. #include <curses.h>
  6. #undef    pnoutrefresh
  7.  
  8. #ifdef PDCDEBUG
  9. char *rcsid_pnoutref = "$Header: C:\CURSES\portable\RCS\pnoutref.c 2.1 1993/06/18 20:20:44 MH Rel MH $";
  10. #endif
  11.  
  12.  
  13.  
  14.  
  15. /*man-start*********************************************************************
  16.  
  17.   pnoutrefresh()    - refresh pad without updating physical screen
  18.  
  19.   X/Open Description:
  20.      The prefresh routine copies the specified pad to the physical
  21.      terminal screen.  It takes account of what is already
  22.      displayed on the screen to optimize cursor movement.
  23.  
  24.      The pnoutrefresh routine copies the named pad to the virtual
  25.      screen. It then compares the virtual screen with the physical
  26.      screen and performs the actual update.
  27.  
  28.      These routines are analogous to the routines wrefresh and
  29.      wnoutrefresh except that pads, instead of windows, are
  30.      involved.  Additional parameters are also needed to indicate
  31.      what part of the pad and screen are involved. The upper left
  32.      corner of the part of the pad to be displayed is specified by
  33.      py and px.  The coordinates sy1, sx1, sy2, and sx2 specify the
  34.      edges of the screen rectangle that will contain the selected
  35.      part of the pad.
  36.  
  37.      The lower right corner of the pad rectangle to be displayed is
  38.      calculated from the screen co-ordinates.  This ensures that
  39.      the screen rectangle and the pad rectangle are the same size.
  40.  
  41.      Both rectangles must be entirely contained within their
  42.      respective structures.
  43.  
  44.   PDCurses Description:
  45.      Contrary to the statements above, the pnoutrefresh() routine
  46.      will not perform an update to the physical screen.  This task
  47.      is performed by doupdate().
  48.  
  49.   X/Open Return Value:
  50.      The prefresh() function returns OK on success and ERR on error.
  51.  
  52.   PDCurses Errors:
  53.      It is an error to pass a null WINDOW* pointer.
  54.  
  55.   Portability:
  56.      PDCurses    int pnoutrefresh( WINDOW* w, int py, int px,
  57.                          int sy1, int sx1,
  58.                          int sy2, int sx2 );
  59.      X/Open Dec '88    int pnoutrefresh( WINDOW* win, int py, int px,
  60.                          int sy1, int sx1,
  61.                          int sy2, int sx2 );
  62.      SYS V Curses    int pnoutrefresh( WINDOW* win, int py, int px,
  63.                          int sy1, int sx1,
  64.                          int sy2, int sx2 );
  65.  
  66. **man-end**********************************************************************/
  67.  
  68. int    pnoutrefresh(WINDOW* w,int py,int px,int sy1,int sx1,int sy2,int sx2)
  69. {
  70.     WINDOW*        s = curscr;
  71.     int        sline = sy1;
  72.     int        pline = py;
  73.     int        num_cols = min((sx2-sx1+1),(w->_maxx-px));
  74.  
  75. #ifdef PDCDEBUG
  76.     if (trace_on) PDC_debug("pnoutrefresh() - called\n");
  77. #endif
  78.  
  79.  
  80.     if (w == (WINDOW *)NULL)
  81.         return( ERR );
  82.  
  83.     while (sline <= sy2)
  84.     {
  85.         if (pline < w->_maxy)
  86.         {
  87.             memcpy(&(s->_y[sline][sx1]),
  88.                    &(w->_y[pline][px]),
  89.                    (num_cols) * sizeof(chtype));
  90.  
  91.             if ((s->_firstch[sline] == _NO_CHANGE) ||
  92.                 (s->_firstch[sline] > sx1))
  93.             {
  94.                 s->_firstch[sline] = sx1;
  95.             }
  96.  
  97.             if (sx2 > s->_lastch[sline])
  98.                 s->_lastch[sline] = sx2;
  99.  
  100.             w->_firstch[pline] = _NO_CHANGE;  /* updated now */
  101.             w->_lastch[pline] = _NO_CHANGE;  /* updated now */
  102.         }
  103.         sline++;
  104.         pline++;
  105.     }
  106.  
  107.     if (w->_clear)
  108.     {
  109.         w->_clear = FALSE;
  110.         s->_clear = TRUE;
  111.     }
  112.  
  113. /* position the cursor to the pad's current position if possible */
  114.     if (!w->_leave)
  115.     {
  116. /* is the pad current position going to end up displayed ? if not */
  117. /* then don't move the cursor, if so move it to the correct place */
  118.         if (w->_cury >= py
  119.         &&  w->_curx >= px
  120.         &&  w->_cury <= py + (sy2 - sy1+1)
  121.         &&  w->_curx <= px + (sx2 - sx1+1))
  122.             {
  123.                 s->_cury = (w->_cury - py) + sy1;
  124.                 s->_curx = (w->_curx - px) + sx1;
  125.             }
  126.     }
  127.     return( OK );
  128. }
  129.